﻿//扩展format
Date.prototype.format = function (fmt) { //author: meizz   
    var o = {
        "M+": this.getMonth() + 1,                 //月份   
        "d+": this.getDate(),                    //日   
        "h+": this.getHours(),                   //小时   
        "m+": this.getMinutes(),                 //分   
        "s+": this.getSeconds(),                 //秒   
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
        "S": this.getMilliseconds()             //毫秒   
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};

function compareDate(d1, d2) {
    var arrayD1 = d1.split("-");
    var date1 = new Date(arrayD1[0], arrayD1[1], arrayD1[2]);
    var arrayD2 = d2.split("-");
    var date2 = new Date(arrayD2[0], arrayD2[1], arrayD2[2]);
    if (date1 < date2) return false;
    return true;
}

function getBeforeDate(nDay) {
    var n = nDay;
    var d = new Date();
    d.setDate(d.getDate() - n);
    var year = d.getFullYear();
    var mon = d.getMonth();
    var day = d.getDate();
    return new Date(year, mon, day);
}
//权限用户
var userName = '';
//权限类型
var customUserType = 0;
//获取日期
var newDate = new Date();
//是否可输入
var isEdit = true;
//设置默认开始时间-提前一个月
newDate.setDate(newDate.getMonth() - 1);
//巡检主单Id
var tifId = 0;
//问题跟进主单Id
var tfId = 0;
//巡检时间
var tif_checkDate = new Date();
//店铺编码
var shopCode = '';
//全局Ajax请求url
var post_url = 'FollowMaster.ashx';
//Ajax请求
var postFun = function (_postUrl, _param, _callback) {
    $.ajax({
        type: "post",
        url: _postUrl,
        data: _param,
        dataType: "json",
        success: function (datas) {
            if (_callback) {
                _callback(datas);
            }
        }
    });
};
//图片对象
var imgVo = { Url: '', ImageId: '', tf_id: '' };
//图片查看器-图片数组
var dataList = [];
//设置图片容器
var setImgList = function () {
    var imgItem = $(".img64");
    dataList = [];
    for (var i = 0; i < imgItem.length; i++) {
        dataList.push(imgItem[i].src);
    }
};
//设置图片查看器
var setImgView = function () {
    setImgList();
    var imgItem = $(".img64");
    for (var j = 0; j < imgItem.length; j++) {
        imgItem[j].index = j;
        imgItem[j].addEventListener("click",
            function (event) {
                var src = event.target.attributes[1].value;
                var options = {
                    dataList: dataList,
                    currentSrc: src,
                    show_remove_btn: false,
                    remove: function (src, next) {
                        if (isEdit) {
                            var box = $("img[src='" + src + "']");
                            var imageId = $(box).parent().find('.ImageId').val();
                            removeImg(imageId,
                                function (result) {
                                    if (result) {
                                        var imgBoxs = $(box).parents('.addImgBoxs');
                                        $(box).parents('.ImgBox').remove();
                                        var imgBox = $(imgBoxs).find('.ImgBox');
                                        if (imgBox.length >= 10) {
                                            $(imgBoxs).parents('td').find('.upload_wwh').hide();
                                        } else {
                                            $(imgBoxs).parents('td').find('.upload_wwh').show();
                                        }
                                        if (next) {
                                            next();
                                        }
                                    }
                                });
                        }
                    }
                };
                ImgView("imgView", options);
            });
    }
};
//当前操作行
var currentRowId = 0;
//设置行号
function reSetRowId() {
    var objTable = document.getElementById("addTable");
    var length = objTable.rows.length - 1;
    if (length >= 0) {
        for (var i = 1; i <= length; i++) {
            objTable.rows[i].cells[0].innerText = i;
        }
    }
}
//获取创建时的表格数据
var getAllRowData = function () {
    var detaliData = [];
    var objTable = document.getElementById("addTable");
    var length = objTable.rows.length - 1;
    for (var i = 1; i <= length; i++) {
        var row = objTable.rows[i];
        var can_sel = $(row).find('.ck-item').is(':checked');
        if (can_sel) {
            var dataItem = getRowData(i);
            detaliData.push(dataItem);
        }
    }
    return detaliData;
};

//获取指定行数据
function getRowData(index) {
    var row = getRow(index);
    //问题明细对象
    var followDetail = {
        tfd_id: 0,
        tf_id: tfId,
        tid_id: 0,
        tfd_question: '',
        tid_remarks: '',
        tid_points: 0.0,
        tfd_correctiveRecommendations: '',
        tfd_finish_date: '',
        kmImgVOList: [],
        tfd_responsible: ''
    };
    followDetail.tf_id = tfId;
    followDetail.tfd_id = parseInt($(row).find('.tfd_id').val());
    followDetail.tid_id = parseInt($(row).find('.tid_id').val());
    followDetail.tfd_correctiveRecommendations = $.trim($(row).find('.tfd_correctiveRecommendations').val());
    followDetail.tfd_finish_date = $(row).find('.tfd_finish_date').val();
    followDetail.tfd_responsible = $.trim($(row).find('.tfd_responsible').val());
    var imgBoxList = $(row).find('.addImgBoxs .ImgBox');
    if (imgBoxList.length > 0) {
        followDetail.kmImgVOList = [];
        for (var i = 0; i < imgBoxList.length; i++) {
            var item = imgBoxList[i];
            var ImageId = $(item).find('.ImageId').val();
            imgVo = {};
            imgVo.ImageId = ImageId;
            imgVo.tf_id = followDetail.tfd_id;
            imgVo.Url = '';
            followDetail.kmImgVOList.push(imgVo);
        }
    }
    return followDetail;
}
//获取行内容
function getRow(index) {
    var objTable = document.getElementById("addTable");
    var length = objTable.rows.length - 1;
    if (index > 0 && index <= length) {
        var row = objTable.rows[index];
        return row;
    }
}
//根据图片ID删除图片
function removeImg(ImageId, callback) {
    if (ImageId) {
        var del_param = { action: 'DeleteOSS', Id: ImageId };
        postFun('../ImageHandler.ashx', del_param, function (json) {
            if (json.Success) {
                Ext.net.Notification.show({
                    html: '删除图片成功！',
                    title: '操作提示'
                });
            } else {
                Ext.net.Notification.show({
                    html: '删除图片失败，请稍后再试！',
                    title: '操作提示'
                });
            }
            if (callback) {
                callback(json.Success);
            }
        });
    }
}
//删除图片按钮事件
function btnRemoveImg(ele) {
    var ImgBox = $(ele).parents('.ImgBox');
    var ImageId = $(ImgBox).find('.ImageId').val();
    removeImg(ImageId, function (result) {
        if (result) {
            var imgBoxs = $(ImgBox).parents('.addImgBoxs');
            $(ImgBox).remove();
            var imgBox = $(imgBoxs).find('.ImgBox');
            if (imgBox.length >= 10) {
                $(imgBoxs).parents('td').find('.upload_wwh').hide();
            } else {
                $(imgBoxs).parents('td').find('.upload_wwh').show();
            }
        }
    });
}
//鼠标经过图片
function imgMouseover(ele, type) {
    if (!isEdit) return;
    var btns = $(ele).find('.img-box-btns');
    if (type == 1) {
        btns.removeClass('hide');
    } else {
        btns.addClass('hide');
    }
}
//增加图片--带删除按钮
function addImgItem(data, row) {
    if (data != null) {
        var addImgBoxs = $(row).find('.addImgBoxs');
        $(row).find('.ck-item').prop('checked', 'checked');
        var imgBox = $(addImgBoxs).find('.ImgBox');
        //超过三张就隐藏
        if (imgBox.length >= 2) {
            $(row).find('.upload_wwh').hide();
        }
        var addHtml = "<div class='ImgBox pint-img' onMouseMove='imgMouseover(this,1)' onMouseOut='imgMouseover(this,2)'>" +
            "<div class='img'><span>" +
            "<img class='img64 pint-img' src= '" + data.Url + "' />" +
            "<input type='hidden' class='ImageId' value='" + data.ImageId + "'/>" +
            "</span>" +
            "<div class='img-box-btns hide'><i class='icon-search close-btn' onClick='btnRemoveImg(this)'></i></div>" +
            "</div ></div>";
        addImgBoxs.append(addHtml);
        setImgView();
    }
}
//增加图片--不带删除按钮
function addTidImgItem(data, row) {
    if (data != null) {
        var tidImgBoxs = $(row).find('.tidImgBoxs');
        var addHtml = "<div class='ImgBox pint-img' >" +
            "<div class='img'><span>" +
            "<img class='img64 pint-img' src= '" + data.Url + "' />" +
            "</span></div ></div>";
        tidImgBoxs.append(addHtml);
        setImgView();
    }
}
//设置行数据
function setRowData(data) {
    var row = getRow(currentRowId);
    if (data != null) {
        $(row).find('.tfd_id').val(data.tfd_id);
        $(row).find('.tid_id').val(data.tid_id);
        $(row).find('.tfd_question').text($.trim(data.tfd_question));
        $(row).find('.tid_points').text(data.tid_points);
        $(row).find('.tid_remarks').text($.trim(data.tid_remarks));
        //tidImgBoxs
        var tidImgJson = data.tidImgVoList;
        if (tidImgJson != null && tidImgJson.length > 0) {
            var boxs = $(row).find('.tidImgBoxs').empty();
            for (var i = 0; i < tidImgJson.length; i++) {
                addTidImgItem(tidImgJson[i], row);
            }
        }
        var tcr = $.trim(data.tfd_correctiveRecommendations);
        if (tcr != '' && tcr != null) {
            $(row).find('.ck-item').prop('checked', true);
        } else {
            $(row).find('.ck-item').removeProp('checked');
        }
        $(row).find('.tfd_correctiveRecommendations').val($.trim(data.tfd_correctiveRecommendations));
        $(row).find('.tfd_finish_date').val(data.tfd_finish_date != null ? new Date(data.tfd_finish_date).format('yyyy-MM-dd') : '');
        $(row).find('.tfd_responsible').val($.trim(data.tfd_responsible));
        var imgJson = data.kmImgVOList;
        if (imgJson != null && imgJson.length > 0) {
            for (var i = 0; i < imgJson.length; i++) {
                addImgItem(imgJson[i], row);
            }
        }
    }
}
//清空表格数据
function emptyTableData() {
    var objTable = document.getElementById("addTable");
    var length = objTable.rows.length - 1;
    while (length > 0) {
        objTable.deleteRow(1);
        length -= 1;
    }
}



//清空表单数据
function emptyFromData() {
    $('.tf_sm_name').val("");
    $('.tf_sm_reCheckRemarks').val("");
    $('.tf_sm_date').val("");
    $('.tf_sv_name').val("");
    $('.tf_sv_reCheckRemarks').val("");
    $('.tf_sv_date').val("");
    $(":radio[name='tf_shopType']").removeAttr("checked");
}


//绑定表格数据 
function bindTableData(json) {
    emptyTableData();
    if (json != null && json.length > 0) {
        for (var i = 0; i < json.length; i++) {
            AddRow();
            var data = json[i];
            setRowData(data);
        }
    }
}

//增加行
function AddRow() {
    //增加问题跟进明细
    var objTable = document.getElementById("addTable");
    currentRowId = objTable.rows.length;
    var nextRow = objTable.insertRow(currentRowId);
    var str_td = "<td style='width:45px;text-align:center;padding: 0px;' class='rowId pint-hide'><input type='checkbox' class='ck-item'/></td>";
    str_td += "<td style='width:auto; min-width:400px;text-align:left; '><span><span class='tfd_question'></span><i style='color: red; '>(<i class='tid_points'></i>分)</i><input type='hidden' class='tid_id' value='0'/></span></td>";
    str_td += "<td style='width:200px;text-align:left;'><div class='tid_remarks'></div><input type='hidden' class='tfd_id' value='0'/></td>";
    str_td += "<td style='width:198px;' class='pint-hide'><div class='tidImgBoxs'></div></td>";
    str_td += "<td style='width:200px;text-align:center;'><textarea class='tfd_correctiveRecommendations' value=''></textarea></td>";
    str_td += "<td style='width:200px;' class='pint-hide'>";
    str_td += "<div class='addImgBoxs'></div>";
    str_td += "<div class='upload_wwh pint-hide'></div>";
    str_td += "</td> ";
    str_td += "<td style='width:110px;text-align:center;'>";
    str_td += "<input type='text' name= 'tfd_finish_date' style='padding:0px 2px;' datacol= 'yes' err= '完成时间' value='' checkexpession= 'NotNull' maxlength= '10' class='form-control required tfd_finish_date'/></td > ";
    str_td += "<td style='width:100px;text-align:center'><input class='tfd_responsible' type='text' style='width:100%; height:30px;' /></td>";
    nextRow.innerHTML = str_td;
    nextRow.className = "cyl_tr";
    var row = getRow(currentRowId);
    if (isEdit) {
        $(row).find('.upload_wwh').imgUpload({
            path: '../ImageHandler.ashx?action=UploadOSS',
            onSuccess: function (res) {
                if (res.Success) {
                    Ext.net.Notification.show({
                        html: '上传图片成功！',
                        title: '操作提示'
                    });
                    var data = res.Data;
                    if (data) {
                        addImgItem(data, row);
                    }
                } else {
                    Ext.net.Notification.show({
                        html: res.Message,
                        title: '操作提示'
                    });
                }
            },
            onFailure: function (res) {
                Ext.net.Notification.show({
                    html: '上传图片失败！',
                    title: '操作提示'
                });
                console.log(res);
            }
        });
        $(row).find('.tfd_finish_date').attr("readonly", "readonly");
        $(row).find('.tfd_finish_date').datepicker({
            format: "yyyy-mm-dd",
            language: "zh-CN",
            autoclose: true,
            todayHighlight: true,
            startDate: newDate
        });
        var ckbox = $(row).find('.ck-item');
        $(row).find('.tfd_finish_date').change(function () {
            ckbox.prop('checked', 'checked');
        });
        $(row).find('.tfd_correctiveRecommendations').change(function () {
            ckbox.prop('checked', 'checked');
        });
        $(row).find('.tfd_responsible').change(function () {
            ckbox.prop('checked', 'checked');
        });
    } else {
        disabledTableInput();
    }
}
//验证数据状态
var validataTableData = function () {
    var list = getAllRowData();
    var result = { msg: '', data: 1 };
    if (list != null && list.length > 0) {
        for (var i = 0; i < list.length; i++) {
            var item = list[i];
            var index = i + 1;
            if (item.tfd_correctiveRecommendations == null || item.tfd_correctiveRecommendations == "") {
                result.msg = "第" + index + "条明细&quot;整改措施及处罚情况&quot;为空，请填写！";
                result.data = 0;
                break;
            }
            if (item.tfd_finish_date == null || item.tfd_finish_date == "") {
                result.msg = "第" + index + "条明细&quot;完成时间&quot;为空，请填写！";
                result.data = 0;
                break;
            }
            if (item.tfd_responsible == null || item.tfd_responsible == "") {
                result.msg = "第" + index + "条明细&quot;责任人&quot;为空，请填写！";
                result.data = 0;
                break;
            }
        }
    }
    return result;
};
//保存方法
var savaFollowMaster = function (callback) {
    var btn = $('#btnSava');
    if (shopCode == "") {
        Ext.net.Notification.show({
            html: '请先选择店铺',
            title: '提示'
        });
        $(btn).removeAttr("disabled");
        return false;
    }
    var dataList = getAllRowData();
    if (dataList.length == 0) {
        Ext.net.Notification.show({
            html: '请选择问题列表！',
            title: '提示'
        });
        $(btn).removeAttr("disabled");
        return false;
    }
    var _creator = $("[name='UserId']").val();
    layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
    var detalis = getAllRowData();
    var _follow = {
        tf_id: tfId,
        tif_id: tifId,
        creator: _creator,
        AreaName: $('.AreaName').text(),
        tf_shopType: $('input:radio[name="tf_shopType"]:checked').val(),
        tif_shopName: $('.tif_shopName').text(),
        tif_storeManager: $('.tif_storeManager').text(),
        tif_shopManager: $('.tif_shopManager').text(),
        tf_rectificationTime: $('.tf_rectificationTime').text(),
        tif_score: $('.tif_score').text(),
        tif_questionCount: $('.tif_questionCount').text(),
        tif_shopLevel: $('.tif_shopLevel').text(),
        tf_sm_name: $.trim($('.tf_sm_name').val()),
        tf_sm_reCheckRemarks: $.trim($('.tf_sm_reCheckRemarks').val()),
        tf_sm_date: $.trim($('.tf_sm_date').val()),
        tf_sv_name: $.trim($('.tf_sv_name').val()),
        tf_sv_reCheckRemarks: $.trim($('.tf_sv_reCheckRemarks').val()),
        tf_sv_date: $.trim($('.tf_sv_date').val()),
        DetailVOList: detalis
    };
    //检证数据 --后面补上
    //保存
    var sava_param = { action: 'SavaFollow', follow: JSON.stringify(_follow) };
    $.ajax({
        type: "post",
        url: post_url,
        data: sava_param,
        dataType: "json",
        success: function (datas) {
            layer.closeAll('dialog');
            if (datas.Data == null) {
                Ext.net.Notification.show({
                    html: '保存出错!',
                    title: '操作提示'
                });
            } else {
                Ext.net.Notification.show({
                    html: '保存成功!',
                    title: '操作提示'
                });
            }
            if (callback != null) {
                callback(datas.Data);
            }
        }
    });
};
//关闭表格输入项
var disabledTableInput = function () {
    $(".tfd_question").attr("readonly", "readonly");
    $(".tfd_correctiveRecommendations").attr("readonly", "readonly");
    $(".tfd_finish_date").attr("disabled", true);
    $(".tfd_responsible").attr("readonly", "readonly");
};
//关闭用户输入
var disabledAll = function () {
    isEdit = false;
    $('#btnSava').attr("disabled", true);
    $('.tf_sm_name').attr("readonly", "readonly");
    $('.tf_sm_reCheckRemarks').attr("readonly", "readonly");
    $('.tf_sm_date').attr("disabled", true);
    $('.tf_sv_name').attr("readonly", "readonly");
    $('.tf_sv_reCheckRemarks').attr("readonly", "readonly");
    $('.tf_sv_date').attr("disabled", true);
    $("input[name='tf_shopType']").attr("disabled", true);
    disabledTableInput();
};
//打开用户输入
var enabledAll = function () {
    isEdit = true;
    $('#btnSava').removeAttr("disabled");
    $('.tf_sm_name').removeAttr("readonly");
    $('.tf_sm_reCheckRemarks').removeAttr("readonly");
    $('.tf_sm_date').removeAttr("disabled");
    $('.tf_sv_name').removeAttr("readonly");
    $('.tf_sv_reCheckRemarks').removeAttr("readonly");
    $('.tf_sv_date').removeAttr("disabled");
    $("input[name='tf_shopType']").removeAttr("disabled");
    $(".tfd_question").removeAttr("readonly");
    $(".tfd_correctiveRecommendations").removeAttr("readonly");
    $(".tfd_finish_date").removeAttr("disabled");
    $(".tfd_responsible").removeAttr("readonly");
};
//角色设置
var setRule = function (json) {
    tif_checkDate = new Date(json.tif_checkDate);
    var ckTime = "";
    userName = $("[name='UserName']").val();
    customUserType = parseInt($("[name='CustomUserType']").val());
    $('.tf_sm_name').val($.trim(json.tf_sm_name));
    $('.tf_sm_date').val(json.tf_sm_date != null ? new Date(json.tf_sm_date).format('yyyy-MM-dd') : '');
    $('.tf_sm_reCheckRemarks').val($.trim(json.tf_sm_reCheckRemarks));
    $('.tf_sv_name').val($.trim(json.tf_sv_name));
    $('.tf_sv_date').val(json.tf_sv_date != null ? new Date(json.tf_sv_date).format('yyyy-MM-dd') : '');
    $('.tf_sv_reCheckRemarks').val($.trim(json.tf_sv_reCheckRemarks));
    if (customUserType == 2) {
        isEdit = false;
        //店铺经理(区域经理)
        disabledAll();
        if (json.tf_sm_name == null || $.trim(json.tf_sm_name) == "") {
            ckTime = getBeforeDate(30);
            if (compareDate(tif_checkDate.format('yyyy-MM-dd'), ckTime.format('yyyy-MM-dd'))) {
                $('.tf_sm_reCheckRemarks').val($.trim(json.tf_sm_reCheckRemarks));
                $('.tf_sm_name').val(userName);
                $('.tf_sm_date').val(new Date().format('yyyy-MM-dd'));
                $('.tf_sm_reCheckRemarks').removeAttr('readonly');
                $('#btnSava').removeAttr("disabled");
            } else {
                Ext.net.Notification.show({
                    html: '已经超过审批时间',
                    title: '提示'
                });
            }
        }
    } else if (customUserType == 3) {
        //督导
        disabledAll();
        isEdit = false;
        if (json.tf_sv_name == null || $.trim(json.tf_sv_name) == "") {
            ckTime = getBeforeDate(30);
            if (compareDate(tif_checkDate.format('yyyy-MM-dd'), ckTime.format('yyyy-MM-dd'))) {
                $('.tf_sv_reCheckRemarks').val($.trim(json.tf_sv_reCheckRemarks));
                $('.tf_sv_name').val(userName);
                $('.tf_sv_date').val(new Date().format('yyyy-MM-dd'));
                $('.tf_sv_reCheckRemarks').removeAttr('readonly');
                $('#btnSava').removeAttr("disabled");
            } else {
                Ext.net.Notification.show({
                    html: '已经超过审批时间',
                    title: '提示'
                });
            }
        }
    } else {
        isEdit = false;
        disabledAll();
        ckTime = getBeforeDate(10);
        if (compareDate(tif_checkDate.format('yyyy-MM-dd'), ckTime.format('yyyy-MM-dd'))) {
            if (json.tf_sm_name == null || $.trim(json.tf_sm_name) == "") {
                isEdit = true;
                enabledAll();
                $('.tf_sm_name').attr("readonly", "readonly");
                $('.tf_sm_reCheckRemarks').attr("readonly", "readonly");
                $('.tf_sm_date').attr("disabled", true);
                $('.tf_sv_name').attr("readonly", "readonly");
                $('.tf_sv_reCheckRemarks').attr("readonly", "readonly");
                $('.tf_sv_date').attr("disabled", true);
            }
        } else {
            Ext.net.Notification.show({
                html: '已经超过修改时间',
                title: '提示'
            });
        }
    }
};
//加载完成后执行
$(function () {
    //日期控件初始化--start
    $('.tf_sm_date').datepicker({
        format: "yyyy-mm-dd",
        language: "zh-CN",
        autoclose: true,
        todayHighlight: true,
        startDate: newDate
    });
    $('.tf_sv_date').datepicker({
        format: "yyyy-mm-dd",
        language: "zh-CN",
        autoclose: true,
        todayHighlight: true,
        startDate: newDate
    });
    //全选
    $('.ck-all').click(function () {
        var checked = $('.ck-all').is(':checked');
        if (checked) {
            $('.ck-item').prop('checked', 'checked');
        } else {
            $('.ck-item').removeProp('checked');
        }
    });
    //店铺自动补全控件初始化
    var data_param = { action: 'GetShopList', userId: parseInt($("[name='UserId']").val()) };
    var itemSuggest_shop = new itemSuggest('search-Shops', post_url, 'ShopCode', 'ShopName', data_param);
    itemSuggest_shop.SetBtnHide(false); //隐藏按钮
    itemSuggest_shop.SetMultiWord(false); //关闭多选
    itemSuggest_shop.itemPost();
    //店铺自动补全控件选择
    $('#search-Shops').on('onSetSelectValue', function (e, keyword, data) {
        shopCode = itemSuggest_shop.getSelectIds();
        $("[name='ShopCode']").val(shopCode);
        emptyTableData();
        emptyFromData();

        //查询问题跟进主单
        var f_m_param = { action: 'GetFollowMaster', shopCode: shopCode };
        $.ajax({
            type: "post",
            url: post_url,
            data: f_m_param,
            dataType: "json",
            success: function (datas) {
                if (datas.Data != null) {
                    var json = datas.Data;
                    setRule(json);
                    tfId = json.tf_id;
                    tifId = json.tif_id;
                    $('.AreaName').text(json.AreaName);
                    $('.tif_shopName').text(json.tif_shopName);
                    $('.tif_storeManager').text(json.tif_storeManager);
                    $('.tif_shopManager').text(json.tif_shopManager);
                    $('.tf_rectificationTime').text(json.tf_rectificationTime == null ? new Date().format("yyyy-MM-dd") : new Date(json.tf_rectificationTime).format("yyyy-MM-dd"));
                    $('.tif_score').text(json.tif_score);
                    $('.tif_questionCount').text(json.tif_questionCount);
                    $('.tif_shopLevel').text(json.tif_shopLevel);
                    $('.tf_sm_reCheckRemarks').val(json.tf_sm_reCheckRemarks);
                    $('.tf_sv_reCheckRemarks').val(json.tf_sv_reCheckRemarks);
                    if (json.tf_shopType > 0) {
                        $("input[name='tf_shopType'][value=" + json.tf_shopType + "]").attr("checked", true);
                    } else {
                        $("input[name='tf_shopType']").removeAttr("checked");
                    }
                    //查询问题跟进明细
                    if (json.DetailVOList != null && json.DetailVOList.length > 0) {
                        bindTableData(json.DetailVOList);
                    }
                } else {
                    Ext.net.Notification.show({
                        html: '未找到数据',
                        title: '提示'
                    });
                }
            }
        });
    });
    //保存按钮事件 
    $('#btnSava').click(function () {
        var btn = this;
        $(btn).attr("disabled", true);
        if (shopCode == "") {
            Ext.Msg.alert('操作提示', '请确认选择店铺！');
            $(btn).removeAttr("disabled");
            return false;
        }
        var tf_shopType = $('input:radio[name="tf_shopType"]:checked').val();
        if (tf_shopType == null) {
            Ext.Msg.alert('操作提示', '请确认选择店铺类型！');
            $(btn).removeAttr("disabled");
            return false;
        }
        shopCode = itemSuggest_shop.getSelectIds();
        var valieData = validataTableData();
        if (valieData.data == 0) {
            Ext.Msg.alert('操作提示', valieData.msg);
            $(btn).removeAttr("disabled");
            return false;
        }

        if (customUserType == 2) {
            //验证店铺经理--是否填写意见
            var tf_sm_reCheckRemarks = $('.tf_sm_reCheckRemarks').val();
            if (tf_sm_reCheckRemarks == null || tf_sm_reCheckRemarks == "") {
                Ext.Msg.alert('操作提示', '店铺经理请输入复查情况！');
                $(btn).removeAttr("disabled");
                return false;
            }
        }
        if (customUserType == 3) {
            //验证店铺经理--是否填写意见
            var tf_sv_reCheckRemarks = $('.tf_sv_reCheckRemarks').val();
            if (tf_sv_reCheckRemarks == null || tf_sv_reCheckRemarks == "") {
                Ext.Msg.alert('操作提示', '督导请输入复查情况！');
                $(btn).removeAttr("disabled");
                return false;
            }
        }
        savaFollowMaster(function (data) {
            $(btn).removeAttr("disabled");
            bindTableData(data.DetailVOList);
        });
    });
    //打印事件
    $("#btnPint").click(function () {
        //$("body").height() = $(".borderGray").height() + 10;
        var textar = $('textarea');
        for (var i = 0; i < textar.length; i++) {
            $(textar[i]).text($(textar[i]).val());
        }
        var inputs = $('input');
        for (var i = 0; i < inputs.length; i++) {
            var item = inputs[i];
            $(item).attr('value', $(item).val());
        }
        var tf_shopType = $('input:radio[name="tf_shopType"]:checked').val();
        if (tf_shopType) {
            $("input[name='tf_shopType'][value=" + tf_shopType + "]").attr("checked", true);
        }
        var mainHtml = $('.content-main').html();
        mainHtml = '<div class="myPint">' + mainHtml + '</div>';

        $(mainHtml).print({
            globalStyles: true,//是否包含父文档的样式，默认为true
            mediaPrint: false,//是否包含media='print'的链接标签。会被globalStyles选项覆盖，默认为false
            stylesheet: null,//外部样式表的URL地址，默认为null
            noPrintSelector: ".no-print",//不想打印的元素的jQuery选择器，默认为".no-print"
            iframe: true,//是否使用一个iframe来替代打印表单的弹出窗口，true为在本页面进行打印，false就是说新开一个页面打印，默认为true
            append: null,//将内容添加到打印内容的后面
            prepend: null,//将内容添加到打印内容的前面，可以用来作为要打印内容
            deferred: $.Deferred()//回调函数
        });

    });

    $("#btnExport").click(function () {
        var shopcode = itemSuggest_shop.getSelectIds();
        if (Y.checkNull(shopcode)) {
            return false;
        } else {
            $.ajax({
                type: "post",
                url: post_url,
                data: { action: 'ExportFollowMaster', shopCode: shopcode },
                dataType: "json",
                success: function (data) {
                    if (data.Data != null) {
                        console.log(data);
                        outExcle(data.Data);
                    }
                }
            });
        }
    });
});